using System;
using System.Collections;
using System.Web;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;

namespace Sedna.Core.Controls.Actions
{
    public class FillContextAction : AbstractAction
    {
        private IDictionary fillElements;

        /// <summary>
        /// Dictionary for fill ExecutionContext elements value
        /// key - path to set to
        /// value - value to set
        /// </summary>
        public IDictionary FillElements
        {
            set { fillElements = value; }
        }
        
        public override IActionResult Execute(IExecutionContext executionContext)
        {
            if (fillElements == null)
            {
                return CreateResult(successStatus);
            }

            foreach (object key in fillElements.Keys)
            {
                executionContext.SetPropertyValue(key.ToString(), fillElements[key]);
            }
            
            return CreateResult(successStatus);
        }
    }
}
